package com.xtinno.controller;

import java.util.ArrayList;
import java.util.List;

import cn.com.apollo.platformbase.response.ResponseResult;
import com.xtinno.pojo.dto.LawContentDTO;
import com.xtinno.pojo.dto.LawRetrievalRequestDTO;
import com.xtinno.pojo.dto.LawRetrievalResponseDTO;
import com.xtinno.service.LawReasoningKnowledgeService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 法条知识库.
 *
 * @author lizhen
 * @since 1.0.0
 */
@Tag(name = "法条知识库")
@RestController
@RequestMapping("/lawKnowledge")
@RequiredArgsConstructor
public class LawKnowledgeController {
	@Autowired
	private final LawReasoningKnowledgeService lawReasoningKnowledgeService;

	/**
	 * 法条知识库查询.
	 */
	@PostMapping(value = "/retrieval")
	public ResponseResult<LawRetrievalResponseDTO> lawRetrieval(@RequestBody LawRetrievalRequestDTO lawRetrievalRequestDTO) {
		var results = lawReasoningKnowledgeService.searchKnowledge(lawRetrievalRequestDTO.getCaseTypeCode(), lawRetrievalRequestDTO.getCaseCauseCode(), lawRetrievalRequestDTO.getLawName(), lawRetrievalRequestDTO.getTkxName());
		// TODO: 临时在这里做个转换，找时间处理下
		List<LawContentDTO> laws = new ArrayList<>(results.size());
		for (var result : results) {
			LawContentDTO lawContentDTO = new LawContentDTO();
			lawContentDTO.setLId(result.getLrk_l_id());
			lawContentDTO.setLpId(result.getLrk_lp_id());
			// TODO: 这里不写其他字段了，需要的时候再补.
			laws.add(lawContentDTO);
		}

		LawRetrievalResponseDTO responseDTO = new LawRetrievalResponseDTO();
		responseDTO.setLaws(laws);
		return ResponseResult.ok(responseDTO);
	}
}
